<?php
namespace App\Http\Controllers\ApiAdmin;

use App\Service\Admin\DoctorService;
use Illuminate\Http\Request;

class DoctorController extends BaseController
{
    //医生

    public function __construct(DoctorService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        $pas['status'] = $request->post('status', ''); //1申请中，2拒绝，3通过
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->getList($pages, $pas);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //申请
    public function auth(Request $request)
    {
        $id = $request->post('id', 0);
        $status = $request->post('auth', 0); //1拒绝2通过
        if (!in_array($status, [1, 2])) {
            return $this->toJson(-2, '状态错误');
        }
        $res = $this->db->auth($id, $status);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //代办列表
    public function daibanList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->daibanList($uid, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //代办设置
    public function daibanModify(Request $request)
    {
        $id = $request->post('id', 0);
        $res = $this->db->daibanModify($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //医护列表
    public function yihuList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->yihuList($uid, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //陪诊列表
    public function peizhenList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->peizhenList($uid, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }
}
